﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InterfaceFiles
{
  public class BaseInterfaceRecord : IInterfaceRecord
  {
    internal IInterfaceReader reader;
    internal IInterfaceWriter writer;
    private Dictionary<string, double> data;
    internal List<string> nodes;

    public BaseInterfaceRecord(IInterfaceReader reader, List<string> nodes)
      : this(reader, null, nodes)
    {
    }

    public BaseInterfaceRecord(IInterfaceReader reader, IInterfaceWriter writer, List<string> nodes)
    {
      this.reader = reader;
      this.writer = writer;
      this.nodes = nodes;
      data = new Dictionary<string, double>();
    }

    public DateTime RecordDateTime
    {
      get; 
      set;
    }

    public double TimeStep
    {
      get;
      set;
    }

    public Dictionary<string, double> Data
    {
      get
      {
        return data;
      }
    }

    public virtual void Read()
    {
      int julianDate = reader.ReadInt();
      double secondsOfDay = reader.ReadDouble();
      Console.WriteLine(string.Format("julianDate {0}, secondsOfDay {1}", julianDate, secondsOfDay));
      RecordDateTime = new JulianDate(julianDate);
      RecordDateTime = RecordDateTime.AddSeconds(secondsOfDay);

      double timeStep = reader.ReadDouble();
      TimeStep = timeStep;

      Data.Clear();
      for (int i = 0; i < nodes.Count; i++)
      {
        double dataValue = reader.ReadDouble();
        Data.Add(nodes[i], dataValue);
      }
    }

    public virtual void Write()
    {
      throw new NotImplementedException();
    }
  }
}
